import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_douban/config/app_colors.dart';
import 'package:flutter_douban/model/user_model.dart';

// 头像角色昵称
class DetailHeaderAuthorView extends StatelessWidget {
  final UserModel? model;

  const DetailHeaderAuthorView({
    Key? key,
    this.model,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      height: 60,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          _avatar(),
          _btn(),
        ],
      ),
    );
  }

  /// 头像
  Widget _avatar() {
    return Row(
      children: [
        Container(
          width: 34,
          height: 34,
          decoration: BoxDecoration(
            color: AppColors.page,
            borderRadius: BorderRadius.circular(17),
          ),
          child: ClipOval(
            child: FadeInImage.assetNetwork(
              placeholder: 'assets/images/common/lazy-1.png',
              image: model!.avatar_medium!,
              fit: BoxFit.cover,
            ),
          ),
        ),
        SizedBox(width: 8,),
        _centerview(),
      ],
    );
  }

  /// 中间内容
  Widget _centerview() {
    return Row(
      mainAxisAlignment: MainAxisAlignment.start,
      children: [
        Text(
          model!.nickname!,
          maxLines: 1,
          overflow: TextOverflow.ellipsis,
          style: TextStyle(
            fontSize: 13,
            fontWeight: FontWeight.bold,
            color: AppColors.black,
          ),
        ),
        SizedBox(width: 8,),
        Text(
          'LV.${model!.lvl.toString()}',
          overflow: TextOverflow.ellipsis,
          style: TextStyle(
              fontSize: 11,
              color: AppColors.yellow,
              fontStyle: FontStyle.italic,
              fontWeight: FontWeight.bold
          ),
        ),
      ],
    );
  }

  /// 关注按钮
  Widget _btn() {
    return SizedBox(
      width: 68,
      height: 28,
      child: FlatButton(
        onPressed: () => print(''),
        child: Text(
          '关注',
          style: TextStyle(
            color: Colors.black,
            fontSize: 13,
            fontWeight: FontWeight.w400,
          ),
        ),
        color: Colors.amber,
        shape: RoundedRectangleBorder(
            side: BorderSide(
              color: Colors.amber,
              width: 0.5,
            ),
            borderRadius: BorderRadius.circular(15)),
      ),
    );
  }

}